const seatChart = document.getElementById("seatChart");


// 根据数据生成座位表
function generateSeatChart(cols, names) {
    seatChart.innerHTML = ""; // 清空座位表
    seatChart.style.gridTemplateColumns = `repeat(${cols}, 110px)`; // 接受参数生成列数

    names.forEach((name, index) => {
        const seat = document.createElement("div");
        add_info(seat, name);
        seatChart.appendChild(seat);
    });
}

// 保存数据
function save_data(obj) {
    sendSeatDataToServer(); // 保存函数
    // 提示用户
    obj.innerText = '保存成功';
    setTimeout(() => {
        obj.innerText = '保存记录';
    }, 3000);
}


function add_info(obj, value) {
    obj.className = "seat";
    obj.innerText = value;
    obj.setAttribute("draggable", "true");

    obj.addEventListener("dragstart", dragStart);
    obj.addEventListener("dragover", dragOver);
    obj.addEventListener("drop", drop);
    obj.addEventListener("click", () => editSeatName(obj));
}

// 新增座位
function add_obj() {
    const newSeat = document.createElement("div");
    add_info(newSeat, '');
    seatChart.appendChild(newSeat);  // 末尾插入
    // seatChart.insertBefore(newSeat, seatChart.firstChild); // 最前面插入
}